package com.rfs.juc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @author renfushuai
 * @date 2023/1/4
 */
public class CompletableFutureDemo {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        CompletableFuture<String> completableFutureTest = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("CompletableFuture1 已执行");
            return "dwer1";
        });
        CompletableFuture<String> completableFutureTest2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("CompletableFuture2 已执行");
            return "dwer2";
        });
        TimeUnit.SECONDS.sleep(5);
        String s = completableFutureTest.get();
        System.out.println(s);
    }
}
